﻿<%@ WebHandler Language="C#" Class="receiver" %>

using System;
using System.Diagnostics;
using System.Web;
using System.IO;

public class receiver : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string filename = context.Request.QueryString["filename"].ToString();
        context.Response.Write("Hello World");

        using (FileStream fs = File.Create(context.Server.MapPath("~/App_Data/" + filename)))
        {
            SaveFile(context.Request.InputStream, fs);
        }
    }

    private void SaveFile(Stream stream, FileStream fs)
    {
        byte[] buffer = new byte[4096];
        int bytesRead;
        Debug.Assert(true);
        while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
        {
            fs.Write(buffer, 0, bytesRead);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}